<!DOCTYPE html>
<html>
<head>
    <title>信息管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
    <link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
    <link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="scripts/authority/commonAll.js"></script>
    <script type="text/javascript" src="scripts/jquery/jquery-1.4.4.min.js"></script>
    <script src="scripts/My97DatePicker/WdatePicker.js" type="text/javascript" defer="defer"></script>
    <script type="text/javascript" src="scripts/artDialog/artDialog.js?skin=default"></script>
    <link rel="stylesheet" type="text/css" href="style/authority/jquery-ui-1.10.4.custom.css">
    <link rel="stylesheet" type="text/css" href="style/authority/common.css">
    <link rel="stylesheet" type="text/css" href="style/authority/style.css">
    <script type="text/javascript">
        var id = getUrlParam('id');
        if (id != null) {
            //调用接口
            $.ajax({
                type: "get",
                url: '/info/getInfo/' + id,
                dataType: "json",
                success: function (data) {
                    if (data.success) {
                        $("#bano").val(data.message.bano);
                        $("#address").val(data.message.address);
                        $("#czf").val(data.message.czf);
                        $("#phone").val(data.message.phone);
                        $("#yt").val(data.message.yt);
                        $("#zpf").val(data.message.zpf);
                        $("#zpflx").val(data.message.zpflx);
                        $("#startTime").val(GetDateStr(data.message.starttime));
                        $("#endTime").val(GetDateStr(data.message.endtime));
                    }
                }
            })
        }

        function GetDateStr(date) {
            var dd = new Date(date);                           //后的日期
            var y = dd.getFullYear();
            var m = dd.getMonth() + 1;//获取当前月份的日期
            var d = dd.getDate();
            if(d>9){
                return y + "-" + m + "-" + d;
            }else{
                return y + "-" + m + "-0" + d;
            }
        }

        function save() {
            if (validateForm()) {
                checkFyFhSubmit();
            }
        }

        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]);
            return null; //返回参数值
        }

        /** 检测房源房号是否存在并提交form  **/
        function checkFyFhSubmit() {
            var bano = $("#bano").val();
            var address = $("#address").val();
            var czf = $("#czf").val();
            var zpf = $("#zpf").val();
            var yt = $("#yt").val();
            var zpflx = $("#zpflx").val();
            var startTime = $("#startTime").val();
            var endTime = $("#endTime").val();
            var phone = $("#phone").val();
            var data = {
                "bano": bano,
                "id": id,
                "address": address,
                "czf": czf,
                "zpf": zpf,
                "yt": yt,
                "zpflx": zpflx,
                "startTime": startTime,
                "endTime": endTime,
                "phone": phone
            }
            $.ajax({
                type: "POST",
                url: '/info/addProject',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data),
                dataType: 'json',
                success: function (data) {
                    if (data.success) {
                        window.location.href = "house_list";
                        alert("保存成功")
                    } else {
                        alert(data.message)
                    }
                }
            });
            return true;
        }

        /** 表单验证  **/
        function validateForm() {
            if ($("#bano").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写备案编号', ok: true,});
                return false;
            }
            if ($("#address").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写房屋地址', ok: true,});
                return false;
            }
            if ($("#czf").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写出租方', ok: true,});
                return false;
            }
            if ($("#zpf").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写承租方姓名', ok: true,});
                return false;
            }
            if ($("#yt").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写租赁用途', ok: true,});
                return false;
            }
            if ($("#zpflx").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写承租类型', ok: true,});
                return false;
            }
            if ($("#startTime").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '选择开始时间', ok: true,});
                return false;
            }
            if ($("#endTime").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '选择结束时间', ok: true,});
                return false;
            }
            if ($("#phone").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写手机号', ok: true,});
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<div class="nav nav-nobg">
    <form id="recordQueryForm">
        <input id="key" name="key" type="hidden">
        <table class="nav-table input-table" width="100%" cellspacing="0" cellpadding="0">
            <tbody>
            <tr>
                <th width="30%">备案编号</th>
                <td>
                    <input type="text" id="bano" name="bano" class="required">
                </td>
            </tr>
            <tr>
                <th width="30%">房屋地址</th>
                <td>
                    <input type="text" id="address" name="address" class="required">
                </td>
            </tr>
            <tr>
                <th width="30%">出租方</th>
                <td>
                    <input type="text" id="czf" name="czf" class="required">
                </td>
            </tr>
            <tr>
                <th width="30%">承租方姓名</th>
                <td>
                    <input type="text" id="zpf" name="zpf" class="required">
                </td>
            </tr>
            <tr>
                <th width="30%">租赁用途</th>
                <td>
                    <input type="text" id="yt" name="yt" class="required">
                </td>
            </tr>
            <tr>
                <th width="30%">承租类型</th>
                <td>
                    <input type="text" id="zpflx" name="zpflx" class="required">
                </td>
            </tr>
            <tr>
                <th width="30%">备案有效开始时间</th>
                <td>
                    <input id="startTime" type="text" naem="startTime" class="required"
                           onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
                </td>
            </tr>
            <tr>
                <th width="30%">备案有效结束时间</th>
                <td>
                    <input id="endTime" name="endTime" type="text" class="required"
                           onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
                </td>
            </tr>
            <tr>
                <th width="30%">手机号</th>
                <td>
                    <input type="text" id="phone" name="phone" class="required">
                </td>
            </tr>
            </tbody>
        </table>
        <input type="button" class="button-blue middle" value="保存" onclick="save()">
    </form>
</div>

</body>
</html>